<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="QQ" prop="qq">
        <el-input
          v-model="queryParams.qq"
          placeholder="请输入QQ"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="telephone">
        <el-input
          v-model="queryParams.telephone"
          placeholder="请输入手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品ID" prop="accountMonitoringId">
        <el-input
          v-model="queryParams.accountMonitoringId"
          placeholder="请输入商品ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="queryList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="商品ID" align="center" prop="accountMonitoringId" />
      <el-table-column label="检测时间" align="center" prop="createTime" />
      <el-table-column label="返回文字描述" align="center" prop="msg" />
      <el-table-column label="QQ" align="center" prop="qq" />
      <el-table-column label="手机号" align="center" prop="telephone" />
      <el-table-column label="账号状态" align="center" prop="status" />
      <el-table-column label="脱敏手机号" align="center" prop="bindTel" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改账号监测查询记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="账号监测任务主表id" prop="createId">
          <el-input v-model="form.createId" placeholder="请输入账号监测任务主表id" />
        </el-form-item>
        <el-form-item label="账号监测任务主表id" prop="updateId">
          <el-input v-model="form.updateId" placeholder="请输入账号监测任务主表id" />
        </el-form-item>
        <el-form-item label="-1000：鉴权失败 -1：参数错误 -404：数据未找到 -500：数据操作失败" prop="code">
          <el-input v-model="form.code" placeholder="请输入-1000：鉴权失败 -1：参数错误 -404：数据未找到 -500：数据操作失败" />
        </el-form-item>
        <el-form-item label="返回文字描述" prop="msg">
          <el-input v-model="form.msg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="时间" prop="time">
          <el-input v-model="form.time" placeholder="请输入时间" />
        </el-form-item>
        <el-form-item label="返回的查询的id" prop="queryId">
          <el-input v-model="form.queryId" placeholder="请输入返回的查询的id" />
        </el-form-item>
        <el-form-item label="QQ" prop="qq">
          <el-input v-model="form.qq" placeholder="请输入QQ" />
        </el-form-item>
        <el-form-item label="手机号" prop="telephone">
          <el-input v-model="form.telephone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="账号状态:0=正常,1=被找回,2=二变无,3=今日上限,4=账号错误">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="任务状态:0=待执行,1=执行中,2=已完成,3=异常">
          <el-radio-group v-model="form.taskStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="任务完成时间" prop="taskCompleteTime">
          <el-input v-model="form.taskCompleteTime" placeholder="请输入任务完成时间" />
        </el-form-item>
        <el-form-item label="下次执行时间" prop="taskNextTime">
          <el-input v-model="form.taskNextTime" placeholder="请输入下次执行时间" />
        </el-form-item>
        <el-form-item label="是否启用:0=停用,1=启用" prop="enabled">
          <el-input v-model="form.enabled" placeholder="请输入是否启用:0=停用,1=启用" />
        </el-form-item>
        <el-form-item label="脱敏手机号" prop="bindTel">
          <el-input v-model="form.bindTel" placeholder="请输入脱敏手机号" />
        </el-form-item>
        <el-form-item label="是否停用(1 正常 0 停用)" prop="statusText">
          <el-input v-model="form.statusText" placeholder="请输入是否停用(1 正常 0 停用)" />
        </el-form-item>
        <el-form-item label="账号监测任务主表id" prop="accountMonitoringId">
          <el-input v-model="form.accountMonitoringId" placeholder="请输入账号监测任务主表id" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listQuery, getQuery, delQuery, addQuery, updateQuery, exportQuery } from "@/api/monitor/query";

export default {
  name: "Query",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 账号监测查询记录表格数据
      queryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        createId: null,
        updateId: null,
        code: null,
        msg: null,
        time: null,
        queryId: null,
        qq: null,
        telephone: null,
        status: null,
        taskStatus: null,
        taskCompleteTime: null,
        taskNextTime: null,
        enabled: null,
        bindTel: null,
        statusText: null,
        accountMonitoringId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询账号监测查询记录列表 */
    getList() {
      this.loading = true;
      listQuery(this.queryParams).then(response => {
        this.queryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createId: null,
        updateId: null,
        createTime: null,
        updateTime: null,
        code: null,
        msg: null,
        time: null,
        queryId: null,
        qq: null,
        telephone: null,
        status: "0",
        taskStatus: "0",
        taskCompleteTime: null,
        taskNextTime: null,
        enabled: null,
        bindTel: null,
        statusText: null,
        accountMonitoringId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加账号监测查询记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getQuery(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改账号监测查询记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateQuery(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addQuery(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除账号监测查询记录编号为"' + ids + '"的数据项？').then(function() {
        return delQuery(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有账号监测查询记录数据项？').then(() => {
        this.exportLoading = true;
        return exportQuery(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
